package com.huahua.api.controller;

import com.huahua.api.entity.base.R;
import com.huahua.api.entity.param.CurlExecuteParam;
import com.huahua.api.entity.param.CurlReplaceParam;
import com.huahua.api.entity.vo.CurlExecuteVo;
import com.huahua.api.entity.vo.CurlReplaceVo;
import com.huahua.api.service.CurlService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/curl")
@RequiredArgsConstructor
public class CurlController {

    private final CurlService curlService;

    @PostMapping("/replaceDomain")
    public Mono<R<CurlReplaceVo>> replaceDomain(@RequestBody CurlReplaceParam param) {
        return curlService.replaceDomain(param)
                .map(R::success)
                .onErrorReturn(R.error("系统异常，请稍后重试"));
    }

    @PostMapping("/execute")
    public Mono<R<CurlExecuteVo>> executeCurl(@RequestBody CurlExecuteParam param) {
        return curlService.executeCurl(param)
                .map(R::success)
                .onErrorReturn(R.error("系统异常，请稍后重试"));
    }
}
